package com.rachel.studyapp.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import com.rachel.studyapp.R;
import com.rachel.studyapp.mvp.base.BasePresent;
import com.rachel.studyapp.mvp.base.BaseView;

/**
 * Created by zhengshaorui on 2017/8/11.
 */

public abstract class BaseFragment<T extends BasePresent> extends Fragment implements BaseView {
    private T mPresent;

    @Override
    public void startActivity(Intent intent) {
        getActivity().startActivity(intent);
        getActivity().overridePendingTransition(R.anim.ac_start_in, R.anim.ac_start_out);

    }


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mPresent = initPresent(); //在这里初始化 present
        if (mPresent != null){ //绑定
            mPresent.onAttach(this);
            mPresent.onCreatePresent(); //如果要开始的方法,在这里执行
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mPresent != null){ //销毁
            mPresent.onDeatch();
        }
    }

    public abstract  T initPresent();
}
